﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterSGA.Master" UICulture="pt" Culture="pt-PT" AutoEventWireup="true" CodeBehind="RegisterMailing.aspx.cs" Inherits="SGA.Mailing.RegisterMailing" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <ajaxToolkit:ToolkitScriptManager ID="ScriptManager" runat="server" EnableScriptGlobalization="True"></ajaxToolkit:ToolkitScriptManager>
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="col-md-1    ">
                    <ul class="nav nav-pills nav-stacked">
                        <li class="active">
                            <asp:Button ID="SaveButton" runat="server" Text="Guardar" OnClick="SaveButton_Click" CssClass="btn btn-default navbar-btn" Width="100" ValidationGroup="InsertItem" />
                        </li>
                        <li>
                            <asp:Button ID="ClearButton" runat="server" Text="Cancelar" CssClass="btn btn-default navbar-btn" CausesValidation="False" Width="100" />
                        </li>
                    </ul>
                </div>
                <div class="row">
                    <div class="col-md-10">
                        <asp:EntityDataSource ID="EDSCampaigns" runat="server" DefaultContainerName="MailingEntities" ConnectionString="name=MailingEntities" EntitySetName="Campaigns" EntityTypeFilter="Campaigns" EnableUpdate="True" EnableInsert="True"></asp:EntityDataSource>

                        <asp:EntityDataSource ID="EDSRecipientTypes" runat="server" DefaultContainerName="MailingEntities" ConnectionString="name=MailingEntities" CommandText="select r.id, r.designation, r.designation +' - '+ r.description as description from recipienttypes as r">
                        </asp:EntityDataSource>

                        <asp:EntityDataSource ID="EDSProducts" runat="server" DefaultContainerName="MailingEntities" ConnectionString="name=MailingEntities" CommandText="select p.id, p.productcode, p.productcode+' - '+p.designation as designation from products as p">
                        </asp:EntityDataSource>


                        <div class="row">
                            <div class="col-md-8">
                                <asp:ListView runat="server" ID="LVMailing" DataSourceID="EDSCampaigns" InsertItemPosition="FirstItem" DataKeyNames="Id" OnItemInserting="LVMailing_ItemInserting">
                                    <InsertItemTemplate>
                                        <%--                                        <asp:HiddenField runat="server" Value='<%#Bind("Designation")%>' />
                                        <asp:HiddenField runat="server" Value='<%#Bind("IdThankLettersRepository")%>' />
                                        <asp:HiddenField runat="server" Value='<%#Bind("Designation")%>' />--%>
                                        <div class="row form-group">
                                            <ajaxToolkit:CalendarExtender runat="server" TargetControlID="TextBoxDispatchDate" DaysModeTitleFormat="dd-MM-yyyy" Enabled="True" Format="dd-MM-yyyy" TodaysDateFormat="dd-MM-yyyy" CssClass="MyCalendar"></ajaxToolkit:CalendarExtender>
                                            <div class="col-md-12 form-group form-inline">
                                                <asp:TextBox runat="server" ID="TextBoxYear" CssClass="form-control" placeholder="Ano" MaxLength="2" Width="60" />
                                                <asp:TextBox runat="server" ID="TextBoxMonth" CssClass="form-control" placeholder="Mês" MaxLength="2" Width="60" />
                                                <asp:DropDownList CssClass="form-control" runat="server" ID="DDLRecipientTypes" DataSourceID="EDSRecipientTypes" DataValueField="designation" DataTextField="description"></asp:DropDownList>
                                                <asp:DropDownList CssClass="form-control" runat="server" ID="DDLProducts" DataSourceID="EDSProducts" DataValueField="productcode" DataTextField="Designation"></asp:DropDownList>
                                            </div>
                                            <div class="col-md-9 form-group">
                                                <asp:RequiredFieldValidator runat="server" ErrorMessage="O ano é obrigatório." CssClass="myAlert" ControlToValidate="TextBoxYear" SetFocusOnError="False" ValidationGroup="InsertItem" Display="Dynamic"></asp:RequiredFieldValidator>
                                                <asp:RequiredFieldValidator runat="server" ErrorMessage="O mês é obrigatório." CssClass="myAlert" Display="Dynamic" ControlToValidate="TextBoxMonth" SetFocusOnError="True" ValidationGroup="InsertItem"></asp:RequiredFieldValidator>
                                            </div>
                                            <div class="col-md-8 form-group">
                                                <asp:TextBox runat="server" ID="TextBoxDescription" CssClass="form-control" Text='<%#Bind("Description")%>' placeholder="Descrição" />
                                                <asp:RequiredFieldValidator runat="server" ErrorMessage="A descrição é obrigatória." CssClass="myAlert" Display="Dynamic" ControlToValidate="TextBoxDescription" SetFocusOnError="True" ValidationGroup="InsertItem"></asp:RequiredFieldValidator>
                                            </div>
                                            <div class="col-md-9 form-group form-inline">
                                                <asp:TextBox runat="server" ID="TextBoxDispatchDate" CssClass="form-control" Text='<%#Bind("DispatchDate")%>' placeholder="Data despacho" />
                                                <asp:TextBox runat="server" ID="TextBoxUnitCost" CssClass="form-control" Text='<%#Bind("UnitCost")%>' placeholder="Custo unitário" />
                                            </div>
                                            <div class="col-md-9 form-group">
                                                <asp:RequiredFieldValidator runat="server" ErrorMessage="A data despacho é obrigatória." CssClass="myAlert" Display="Dynamic" ControlToValidate="TextBoxDispatchDate" SetFocusOnError="True" ValidationGroup="InsertItem"></asp:RequiredFieldValidator>
                                                <asp:RequiredFieldValidator runat="server" ErrorMessage="O custo unitário é obrigatória." CssClass="myAlert" Display="Dynamic" ControlToValidate="TextBoxUnitCost" SetFocusOnError="True" ValidationGroup="InsertItem"></asp:RequiredFieldValidator>
                                            </div>
                                        </div>

                                    </InsertItemTemplate>
                                    <EditItemTemplate>
                                        <ajaxToolkit:CalendarExtender runat="server" TargetControlID="TextBoxDispatchDate" DaysModeTitleFormat="dd-MM-yyyy" Enabled="True" Format="dd-MM-yyyy" TodaysDateFormat="dd-MM-yyyy" CssClass="MyCalendar"></ajaxToolkit:CalendarExtender>
                                        <ajaxToolkit:HoverMenuExtender ID="HoverMenu" runat="server"
                                            PopupControlID="PopupMenu"
                                            PopupPosition="Right"
                                            TargetControlID="PopupRow"
                                            PopDelay="50" HoverDelay="20" OffsetX="10" />

                                        <tr runat="server" id="PopupRow">
                                            <td><%#Eval("Designation")%></td>
                                            <td>
                                                <asp:TextBox runat="server" ID="TextBoxDescription" CssClass="form-control" placeholder="Descrição" Text='<%#Bind("Description")%>' /></td>
                                            <td>
                                                <asp:TextBox runat="server" ID="TextBoxDispatchDate" CssClass="form-control" placeholder="Data despacho" Text='<%#Bind("DispatchDate")%>' /></td>
                                            <td>
                                                <asp:TextBox runat="server" ID="TextBoxUnitCost" CssClass="form-control" placeholder="Custo unitário" Text='<%#Bind("UnitCost")%>' /></td>
                                        </tr>

                                        <asp:Panel ID="PopupMenu" runat="server" Width="200" Style="display: none">
                                            <div class="panel panel-default">
                                                <div class="panel-heading">Campanha</div>
                                                <div class="panel-body">
                                                    <asp:LinkButton ID="LinkButtonCancel" runat="server" Text="Cancelar" CommandName="Cancel" CausesValidation="False"></asp:LinkButton>
                                                    <br />
                                                    <asp:LinkButton ID="LinkButtonUpdate" runat="server" Text="Atualizar" CommandName="Update" ValidationGroup="EditItem" CommandArgument='<%#Eval("Id") %>'></asp:LinkButton>
                                                </div>
                                            </div>
                                        </asp:Panel>

                                    </EditItemTemplate>

                                    <ItemTemplate>
                                        <ajaxToolkit:HoverMenuExtender ID="HoverMenu" runat="server"
                                            PopupControlID="PopupMenu"
                                            PopupPosition="Right"
                                            TargetControlID="PopupRow"
                                            PopDelay="50" HoverDelay="20" OffsetX="10" />

                                        <tr runat="server" id="PopupRow">
                                            <td><%#Eval("Designation")%></td>
                                            <td><%#Eval("Description")%></td>
                                            <td><%#Eval("DispatchDate","{0:dd/MM/yyyy}")%></td>
                                            <td><%#Eval("UnitCost","{0:C}")%></td>
                                        </tr>

                                        <asp:Panel ID="PopupMenu" runat="server" Width="200" Style="display: none">
                                            <div class="panel panel-default">
                                                <div class="panel-heading"><%# Eval("Designation")%></div>
                                                <div class="panel-body">
                                                    <asp:LinkButton ID="LinkButtonDelete" runat="server" Text="Remover" CommandName="Delete" CommandArgument='<%#Eval("Id") %>' OnClientClick="javascript:return confirm('Deseja remover o utilizador?')"></asp:LinkButton>
                                                    <br />
                                                    <asp:LinkButton ID="LinkButtonEdit" runat="server" Text="Editar" CommandName="Edit" CommandArgument='<%#Eval("Id") %>'></asp:LinkButton>
                                                </div>
                                            </div>
                                        </asp:Panel>

                                    </ItemTemplate>
                                    <LayoutTemplate>
                                        <table runat="server" class="table table-hover table-bordered">
                                            <tr>
                                                <th>
                                                    <asp:LinkButton runat="server" Text="Número" CommandName="Sort" CommandArgument="Designation"></asp:LinkButton></th>
                                                <th>
                                                    <asp:LinkButton runat="server" Text="Descrição" CommandName="Sort" CommandArgument="Description"></asp:LinkButton></th>
                                                <th>
                                                    <asp:LinkButton runat="server" Text="Data despacho" CommandName="Sort" CommandArgument="DispatchDate"></asp:LinkButton></th>
                                                <th>
                                                    <asp:LinkButton runat="server" Text="Custo unitário" CommandName="Sort" CommandArgument="UnitCost"></asp:LinkButton></th>
                                            </tr>
                                            <tr id="itemPlaceholder" runat="server"></tr>
                                        </table>
                                        <asp:DataPager runat="server" ID="DataPager" PageSize="5">
                                            <Fields>
                                                <asp:NumericPagerField ButtonCount="10" PreviousPageText="Anterior" NextPageText="Seguinte" />
                                            </Fields>
                                        </asp:DataPager>
                                    </LayoutTemplate>
                                </asp:ListView>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</asp:Content>
